<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>登入 - {{ SYSTEM_NAME }}</title>
    <link rel="stylesheet" href="{{ LAYUI_PATH }}layui/css/layui.css" media="all">
    <link rel="stylesheet" href="{{ LAYUI_PATH }}style/admin.css" media="all">
    <link rel="stylesheet" href="{{ LAYUI_PATH }}style/login.css" media="all">
    <script src="https://res.mapo.cc/static/js/jquery.min.js"></script>
</head>
<body>

<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">

    <div class="layadmin-user-login-main">
        <div class="layadmin-user-login-box layadmin-user-login-header">
            <h2>{{ SYSTEM_NAME }}</h2>
            <p>登录</p>
        </div>
        <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-username"
                       for="LAY-user-login-username"></label>
                <input type="text" name="username" id="LAY-user-login-username" lay-verify="required" placeholder="用户名"
                       class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-password"
                       for="LAY-user-login-password"></label>
                <input type="password" name="password" id="LAY-user-login-password" lay-verify="required"
                       placeholder="密码" class="layui-input">
            </div>
            {#            <div class="layui-form-item">#}
            {#                <div class="layui-row">#}
            {#                    <div class="layui-col-xs7">#}
            {#                        <label class="layadmin-user-login-icon layui-icon layui-icon-vercode"#}
            {#                               for="LAY-user-login-vercode"></label>#}
            {#                        <input type="text" name="vercode" id="LAY-user-login-vercode" lay-verify="required"#}
            {#                               placeholder="图形验证码" class="layui-input">#}
            {#                    </div>#}
            {#                    <div class="layui-col-xs5">#}
            {#                        <div style="margin-left: 10px;">#}
            {#                            <img src="https://www.oschina.net/action/user/captcha" class="layadmin-user-login-codeimg"#}
            {#                                 id="LAY-user-get-vercode">#}
            {#                        </div>#}
            {#                    </div>#}
            {#                </div>#}
            {#            </div>#}
            <div class="layui-form-item" style="margin-bottom: 20px;">
                <input type="checkbox" name="remember" id="remember" lay-skin="primary" title="记住密码">
                <a href="forget" class="layadmin-user-jump-change layadmin-link" style="margin-top: 7px;">忘记密码？</a>
            </div>
            <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-login-submit" id="login">登 入
                </button>
            </div>
            <div class="layui-trans layui-form-item layadmin-user-login-other">
                {#          <label>社交账号登入</label>#}
                {#          <a href="javascript:;"><i class="layui-icon layui-icon-login-qq"></i></a>#}
                {#          <a href="javascript:;"><i class="layui-icon layui-icon-login-wechat"></i></a>#}
                {#          <a href="javascript:;"><i class="layui-icon layui-icon-login-weibo"></i></a>#}

                <a href="register" class="layadmin-user-jump-change layadmin-link">注册帐号</a>
            </div>
        </div>
    </div>

    {#    <div class="layui-trans layadmin-user-login-footer">#}
    {#      #}
    {#      <p>© 2018 <a href="http://www.layui.com/" target="_blank">layui.com</a></p>#}
    {#      <p>#}
    {#        <span><a href="http://www.layui.com/admin/#get" target="_blank">获取授权</a></span>#}
    {#        <span><a href="http://www.layui.com/admin/pro/" target="_blank">在线演示</a></span>#}
    {#        <span><a href="http://www.layui.com/admin/" target="_blank">前往官网</a></span>#}
    {#      </p>#}
    {#    </div>#}


</div>

<script src="{{ LAYUI_PATH }}layui/layui.js"></script>
<script>
    if(self!==top){parent.window.location.replace(window.location.href);}
    class utils {
        /*
        获取URL参数
         */
        static getParam(paramName) {
            let paramValue = "";
            let isFound = !1;
            if (window.location.search.indexOf("?") === 0 && window.location.search.indexOf("=") > 1) {
                let arrSource = unescape(window.location.search).substring(1, window.location.search.length).split("&"),
                    i = 0;
                while (i < arrSource.length && !isFound) arrSource[i].indexOf("=") > 0 && arrSource[i].split("=")[0].toLowerCase() === paramName.toLowerCase() && (paramValue = arrSource[i].split("=")[1], isFound = !0), i++
            }
            return paramValue === "" && (paramValue = null), paramValue
        }
        /*
        设置cookie
         */
        static setCookie(c_name, value, expiredays) {
            let exdate = new Date();
            exdate.setDate(exdate.getDate() + expiredays);
            document.cookie = c_name + "=" + escape(value) + ";expires=" + exdate.toDateString() + ";path=/";
        }
        /*
        获取cookie
         */
        static getCookie(c_name) {
            if (document.cookie.length > 0) {
                let c_start = document.cookie.indexOf(c_name + "=");
                if (c_start !== -1) {
                    c_start = c_start + c_name.length + 1
                    let c_end = document.cookie.indexOf(";", c_start);
                    if (c_end === -1)
                        c_end = document.cookie.length
                    return unescape(document.cookie.substring(c_start, c_end))
                }
            }
            return ""
        }
    }
    /*
    按键事件
     */
    document.onkeydown = kid => {
        let evt = (kid) ? kid : window.event;
        if (evt.keyCode === 13) {
            $("#login").trigger('click');
        }
    }

    const status = $("#remember").prop("checked");
    console.log(status);
    layui.config({
        base: '{{ LAYUI_PATH }}' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'user'], function () {
        const $ = layui.$, admin = layui.admin, form = layui.form;
        const jumpurl = utils.getParam('from');
        if (jumpurl != null) {
            layer.msg('请登录后再执行操作！', {icon: 2});
        }
        form.render();
        //提交
        form.on('submit(LAY-user-login-submit)', function (obj) {
            //请求登入接口
            console.log(obj.field.remember ? '记住密码' : '未记住密码');
            window.loading = parent.layer.msg('登录中...', {icon: 16, time: false, shade: 0.3})
            admin.req({
                method: 'post',
                url: '/user/login',
                data: obj.field,
                done: function (res) {
                    layer.msg(res.message, {
                        icon: res.status ? 1 : 2,
                        time: 1500
                    }, function () {
                        if (res.status) {
                            if (obj.field.remember) {
                                utils.setCookie('_username',obj.field.username);
                                utils.setCookie('_password',obj.field.password);
                                utils.setCookie('_remember',obj.field.remember);
                            }
                            window.location.href = jumpurl ? jumpurl : '/';
                        }
                        parent.layer.close(window.loading);
                    });
                    parent.layer.close(window.loading);
                }
            });
        });
    });

</script>
</body>
</html>